package com.crm.business.crm.controller;


import com.crm.business.crm.service.CrmUploadExcelService;
import com.crm.business.crm.service.ICrmHeadquartersBusinessBalanceService;
import com.crm.common.crm.entity.BO.CrmRoiSearchBO;
import com.crm.common.crm.entity.PO.CrmHeadquartersBusinessBalance;
import com.crm.common.ka.core.common.R;
import com.crm.common.ka.core.common.Result;
import com.crm.common.ka.core.entity.BasePage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/crmHeadquartersBusinessBalance")
@Api(tags = "总部余额模块接口")
public class CrmHeadquartersBusinessBalanceController {

    @Autowired
    private ICrmHeadquartersBusinessBalanceService crmHeadquartersBusinessBalanceService;

    @Autowired
    private CrmUploadExcelService uploadExcelService;

    @PostMapping("/queryPageList")
    @ApiOperation("查询列表页数据")
    @ResponseBody
    public Result<BasePage<CrmHeadquartersBusinessBalance>> queryPageList(@RequestBody CrmRoiSearchBO search) {
        BasePage<CrmHeadquartersBusinessBalance> mapBasePage = crmHeadquartersBusinessBalanceService.queryPageList(search);
        return R.ok(mapBasePage);
    }

    @PostMapping("/queryListById/{putinMoneyId}")
    @ApiOperation("根据ID查询多个")
    public Result<CrmHeadquartersBusinessBalance> queryListById(@PathVariable("putinMoneyId") @ApiParam(name = "id", value = "id") Integer id){
        CrmHeadquartersBusinessBalance crmPutinMoney = crmHeadquartersBusinessBalanceService.getListById(id);
        return R.ok(crmPutinMoney);
    }

    @PostMapping("/allExportExcel")
    @ApiOperation("全部导出")
//    @SysLogHandler(behavior = BehaviorEnum.EXCEL_EXPORT,object = "ROI投放金额导出",detail = "全部导出")
    public void allExportExcel(@RequestBody CrmRoiSearchBO search, HttpServletResponse response) {
        search.setPageType(0);
        crmHeadquartersBusinessBalanceService.exportExcel(response, search);
    }

    @PostMapping("/batchExportExcel")
    @ApiOperation("选中导出")
//    @SysLogHandler(behavior = BehaviorEnum.EXCEL_EXPORT,object = "ROI投放金额导出",detail = "选中导出")
    public void batchExportExcel(@RequestBody @ApiParam(name = "ids", value = "id列表") List<Integer> ids, HttpServletResponse response) {
        CrmRoiSearchBO search = new CrmRoiSearchBO();
        search.setPageType(0);
        search.setIds(ids);
        crmHeadquartersBusinessBalanceService.exportExcel(response, search);
    }

}
